﻿<Window x:Class="Demos.Knapsack.View"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:Knapsack="clr-namespace:Demos.Knapsack" Title="Knapsack" Height="450" Width="500">
    <Window.Resources>
        <DataTemplate DataType="{x:Type Knapsack:Mochila}">
            <Canvas ToolTip="{Binding Contenido, UpdateSourceTrigger=PropertyChanged}">
                <Image Source="media\mochila.png" Height="150" Width="130"></Image>
                <Label Canvas.Left="25" Canvas.Top="0" Content="{Binding Capacidad}" 
                       HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="85">
                </Label>
                <Slider Canvas.Left="10" Canvas.Top="130" Width="110"
                        Minimum="1" Maximum="100" IsSnapToTickEnabled="True"
                        Value="{Binding Capacidad}">
                </Slider>
            </Canvas> 
        </DataTemplate>

        <DataTemplate DataType="{x:Type Knapsack:Objeto}">
            <Grid ToolTip="{Binding Contenido}" Opacity="{Binding Opacidad}">
                <Grid.RowDefinitions>
                    <RowDefinition></RowDefinition>
                    <RowDefinition Height="auto"></RowDefinition>
                    <RowDefinition Height="auto"></RowDefinition>
                </Grid.RowDefinitions>
                <Rectangle Stroke="Black" StrokeThickness="1" Name="rectangulo"
                           Height="25" Width="80" Fill="LightGray">
                </Rectangle>
                <Label HorizontalContentAlignment="Center" VerticalContentAlignment="Center" 
                       Content="{Binding Contenido}"
                       Height="{Binding ElementName=rectangulo, Path=Height}" 
                       Width="{Binding ElementName=rectangulo, Path=Width}">
                </Label>
                
                <StackPanel Grid.Row="1" Orientation="Horizontal">
                    <Label>Valor: </Label>
                    <Label Content="{Binding Valor}"></Label>
                </StackPanel>

                <StackPanel Grid.Row="2" Orientation="Horizontal">
                    <Label>Peso: </Label>
                    <Label Content="{Binding Peso}"></Label>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </Window.Resources>
    
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        
        <ItemsControl ItemsSource="{Binding ContenidoVisual}" BorderBrush="Transparent" Name="Control">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas SizeChanged="WindowOnSizeChanged"></Canvas>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemContainerStyle>
                <Style>
                    <Setter Property="Canvas.Left" Value="{Binding X}" />
                    <Setter Property="Canvas.Top" Value="{Binding Y}" />
                </Style>
            </ItemsControl.ItemContainerStyle>
        </ItemsControl>
        
        <Border Grid.Row="1" BorderBrush="LightGray" BorderThickness="1" Margin="5">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition Width="0.5*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <GroupBox Header="Añadir Objeto" Margin="5">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition></ColumnDefinition>
                        </Grid.ColumnDefinitions>

                        <Label>Contenido:</Label>
                        <TextBox Grid.Column="1" Margin="2"
                                 Text="{Binding ContenidoNuevo, UpdateSourceTrigger=PropertyChanged}"></TextBox>
                        <Label Grid.Column="2">Valor:</Label>
                        <TextBox Grid.Column="3" Margin="2"
                                 Text="{Binding ValorNuevo}"></TextBox>
                        <Label Grid.Row="1">Peso:</Label>
                        <TextBox Grid.Row="1" Grid.Column="1" Margin="2"
                                 Text="{Binding PesoNuevo}"></TextBox>
                        <Button Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" Margin="10,5,10,0"
                                Command="{Binding AñadirObjetoCommand}">Añadir</Button>
                    </Grid>
                </GroupBox>
                
                <StackPanel Grid.Column="1" Margin="10">
                    <Button Margin="5,0,5,0" Command="{Binding EjecutarCommand}">Ejecutar</Button>
                    <Button Margin="5,5,5,0" Command="{Binding BorrarTodoCommand}">Borrar todo</Button>
                    <Button Margin="5,5,5,0" Click="SalirClick">Salir</Button>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</Window>
